<!DOCTYPE html>
<html lang="zxx">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    <link rel="icon" href="images/favicon.png">
    <title></title>

    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <link rel="stylesheet" href="../css/materialize.css">
    <link rel="stylesheet" href="../css/loaders.css">
    <link rel="stylesheet" href="../css/lightbox.css">
    <link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
    <link rel="stylesheet" href="../css/owl.carousel.min.css">
    <link rel="stylesheet" href="../css/owl.theme.default.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/layer.css">

</head>
<style>
    .segments-page {
        padding: 68px 20px 25px;
    }

    .input-radio {
        margin: 0 0 10px 0;
        display: inline-block;
    }

    .radio {
        text-align: center;

    }
</style>
<body>

<!-- navbar -->
<div class="navbar">
    <div class="container">
        <div class="row">
            <div class="col s9">
                <div class="content-left" onclick="javascript:history.back(-1);">
                    <i class="fa fa-chevron-left center"></i>
                </div>
            </div>

        </div>
    </div>

</div>
<!-- end navbar -->

<!-- sidebar -->

<!-- end sidebar -->

<!-- list -->
<div class="segments-page">
    <div class="pages-title">
        <h3>发布订单</h3>
        <div class="line"></div>
    </div>
    <form id="form" onsubmit="return false" action="#" method="post">
        <input type="hidden" name="bankId" id="bankId" value="">
        <input type="hidden" name="patternId" id="patternId" value="">
        <input id="consent" type="checkbox" name="consent" value="1"/>
        <div class="radio">
            <div class="input-radio">
                <input id="orange" type="radio" name="sellType" value="1" checked/>
                <label for="orange">卖出</label>
            </div>
            <div class="input-radio">
                <input id="apple" type="radio" name="sellType" value="2"/>
                <label for="apple">买入</label>
            </div>
        </div>
        <input type="number" min=10000 name="number" id="number" placeholder="数量">
        <input type="text" name="unit_price" value="1.0" id="unit_price" placeholder="请选择单价">
        <div id="poundage"><p>订单手续费<samp id="sxf"></samp></p></div>
        <input type="text" id="total" placeholder="总价" disabled="disabled">
        <input type="text" name="pattern" value="" id="pattern" placeholder="交易方式">
        <input type="text" name="bank" id="bank" placeholder="请选择银行卡" style="display: none;">
        <div id="alipay" style="display: none;">
            <input type="text" name="alipay" id="alipayaccount" placeholder="交易账号">
        </div>
        <input type="password" name="TradersPassword" id="TradersPassword" placeholder="交易密码"
               style="margin: 12px 0 20px 0;">

        <button class="button button-full z-depth-1" onclick="addorder();"><i class="fa fa-send"></i>发布</button>
    </form>
</div>
<!-- end list -->

<script src="../js/jquery.min.js"></script>
<script src="../js/materialize.js"></script>
<script src="../js/numscroller.js"></script>
<script src="../js/lightbox.js"></script>
<script src="../js/owl.carousel.min.js"></script>
<script src="../js/main.js"></script>
<script src="../js/layer.js"></script>
<script src="../js/jquery.md5.js"></script>
<script src="../js/index.js"></script>
<script src="../js/uploading.js"></script>
<script src="../js/mobileSelect.js"></script>
<script>
    $(document).ready(function () {
        var Orderurl = 'Order/orderInfo';
        var OrderInfo = api_request(Orderurl, 'GET');
        if (OrderInfo.code == 1) {
            var Order = OrderInfo.data.info;//配置信息
            var data = OrderInfo.data.data;//数量
            var price = OrderInfo.data.price; //单价
            if (Order.poundage != 0.00) {
                $("#poundage").attr("style", "display:block;");
                $("#sxf").append(Order.poundage);
            } else {
                $("#poundage").attr("style", "display:none;");
            }
            var mobileSelect1 = new MobileSelect({
                trigger: '#number',
                title: '数量选择',
                wheels: [
                    {data: data}
                ],
                transitionEnd: function (indexArr, data) {
                },
                callback: function (indexArr, data) {
                    $("#number").val(data[0].value)
                    var number = $('#number').val();//数量
                    var unit_price = $('#unit_price').val();//单价

                    var poundage = document.getElementById("sxf").innerHTML//手续费
                    if (poundage) {
                        var money = number - (number * unit_price) * poundage;
                    } else {
                        var money = number * unit_price;
                    }
                    $("#total").val(money);

                }
            });
            var mobileSelect1 = new MobileSelect({
                trigger: '#unit_price',
                title: '单价选择',
                wheels: [
                    {data: price}
                ],
                transitionEnd: function (indexArr, data) {

                },
                callback: function (indexArr, data) {
                    $("#unit_price").val(data[0].value)
                }
            });
            var patternurl = 'cms/label/name/pattern'; //支付方式接口
            var patternInfo = api_request(patternurl, 'GET');
            if (patternInfo.data) {
                var stringResult = patternInfo.data.split(',');
                var arr = [];
                for (var i = 0; i < stringResult.length; i++) {
                    arr.push({
                        'id': i,
                        'value': stringResult[i],
                    });
                }
            }
            var mobileSelect1 = new MobileSelect({
                trigger: '#pattern',
                title: '交易方式',
                wheels: [
                    {data: arr},
                ],
                transitionEnd: function (indexArr, data) {

                },
                callback: function (indexArr, data) {

                    $("#pattern").val(data[0].value)
                    $("#patternId").val(data[0].id)
                    var type = data[0].id;
                    if (type == 0) {
                        $("#bank").show(); //显示银行卡
                        $("#alipay").hide(); //隐藏支付宝
                        var UserbankList = 'Member/UserbankList';
                        var UserbankList = api_request(UserbankList, 'GET');
                        if (UserbankList.code == 1 && UserbankList.data.data.length != 0) {
                            var bankdata = UserbankList.data.data;
                            var mobileSelect1 = new MobileSelect({
                                trigger: '#bank',
                                title: '卡号选择',
                                wheels: [
                                    {data: bankdata}
                                ],
                                transitionEnd: function (indexArr, data) {

                                },
                                callback: function (indexArr, data) {
                                    $(" #alipayaccount").val("");
                                    $(" #file").val("");
                                    $("#bank").val(data[0].value)
                                    $("#bankId")[0].value = data[0].id;
                                }
                            });
                        } else {
                            $('#bank').attr('placeholder', '暂时未绑定银行卡')
                        }
                    } else {
                        $(" #bankId").val("");
                        $("#alipay").show(); //显示支付宝
                        $("#bank").hide(); //显示支付宝

                    }


                }
            });


        }
    });

    function addorder() {
        var number = $('#number').val();
        var unit_price = $('#unit_price').val();
        var patternId = $('#patternId').val();
        var bankId = $('#bankId').val();
        var alipayaccount = $('#alipayaccount').val();
        var file = $('#file').val();
        var TradersPassword = $('#TradersPassword').val();
        if (!number) {
            layer.open({
                content: '请选择数量!'
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
            return false;
        }
        if (!unit_price) {
            layer.open({
                content: '请选择单价!'
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
            return false;
        }
        if (!patternId) {
            layer.open({
                content: '请选择付款款方式!'
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
            return false;
        }
        if (patternId == 0) {
            if (!bankId) {
                layer.open({
                    content: '请选择银行卡!'
                    , skin: 'msg'
                    , time: 2 //2秒后自动关闭
                });
                return false;
            }

        } else {
            if (!alipayaccount) {
                layer.open({
                    content: '请输入支付账号!'
                    , skin: 'msg'
                    , time: 2 //2秒后自动关闭
                });
                return false;
            }
        }
        if (!TradersPassword) {
            layer.open({
                content: '请输入交易密码!'
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
            return false;
        }
        var params = $('#form').serializeObject();

        var AddOrderurl = 'Order/add_order';
        var AddOrderInfo = api_request(AddOrderurl, 'POST', params);
        console.log(AddOrderInfo)
        if (AddOrderInfo.code == 1) {
            layer.open({
                content: AddOrderInfo.data
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
        }
    }
</script>
</body>
</html>